﻿Imports System.ComponentModel
Imports MapWinGIS
Imports System.Globalization

<Serializable()> Public Class SDSAxisLayer
    Inherits SelfDrawShapeLayer


    Public Class B4TypeConverter
        Inherits ExpandableObjectConverter

        Public Overloads Overrides Function _
        CanConvertFrom(ByVal context As  _
        System.ComponentModel.ITypeDescriptorContext, ByVal _
        sourceType As System.Type) As Boolean
            If (sourceType.Equals(GetType(String))) Then
                Return True
            Else
                Return MyBase.CanConvertFrom(context, _
                    sourceType)
            End If
        End Function

        Public Overloads Overrides Function CanConvertTo(ByVal _
            context As  _
            System.ComponentModel.ITypeDescriptorContext, ByVal _
            destinationType As System.Type) As Boolean
            If (destinationType.Equals(GetType(String))) Then
                Return True
            Else
                Return MyBase.CanConvertTo(context, _
                    destinationType)
            End If
        End Function

        Public Overloads Overrides Function ConvertFrom(ByVal _
            context As  _
            System.ComponentModel.ITypeDescriptorContext, ByVal _
            culture As System.Globalization.CultureInfo, ByVal _
            value As Object) As Object
            If (TypeOf value Is String) Then

                Dim txt As String = CType(value, String)


                Dim fields() As String = txt.Split(New Char() _
               {","})



                Try
                    'fields(0)

                    Return New B4(fields(0), fields(1), fields(2), fields(3))
                Catch
                    Throw New InvalidCastException(value)
                End Try
            Else
                Return MyBase.ConvertFrom(context, culture, _
                    value)
            End If
        End Function

        Public Overloads Overrides Function ConvertTo(ByVal _
            context As  _
            System.ComponentModel.ITypeDescriptorContext, ByVal _
            culture As System.Globalization.CultureInfo, ByVal _
            value As Object, ByVal destinationType As  _
            System.Type) As Object
            If (destinationType.Equals(GetType(String))) Then
                Return value.ToString()
            Else
                Return MyBase.ConvertTo(context, culture, _
                    value, destinationType)
            End If
        End Function

        Public Overloads Overrides Function _
            GetPropertiesSupported(ByVal context As  _
            ITypeDescriptorContext) As Boolean
            Return True
        End Function

        Public Overloads Overrides Function GetProperties(ByVal _
            context As ITypeDescriptorContext, ByVal value As _
            Object, ByVal Attribute() As Attribute) As  _
            PropertyDescriptorCollection
            Return TypeDescriptor.GetProperties(value)
        End Function


    End Class


    <Serializable()> _
    <TypeConverter(GetType(B4TypeConverter))> _
   Public Class B4
        Public Sub New()
            bL = False
            bR = False
            bT = False
            bB = False

        End Sub

        Public Sub New(ByVal l As Boolean, ByVal r As Boolean, ByVal t As Boolean, ByVal b As Boolean)
            bL = l
            bR = r
            bT = t
            bB = b

        End Sub

        Public Overrides Function ToString() As String

            ' Return MyBase.ToString()
            Dim temp As String = bT.ToString() + "," + bB.ToString() + "," + bR.ToString() + "," + bL.ToString()
            Return temp

        End Function

        Public Event ValueChanged()
        

        Dim bL As Boolean
        <CategoryAttribute("四维设置"), _
    DisplayName("左")> _
        Public Property BLProperty() As Boolean
            Get
                Return bL
            End Get
            Set(ByVal value As Boolean)
                bL = value

                RaiseEvent ValueChanged()
            End Set
        End Property

        Dim bR As Boolean
        <CategoryAttribute("四维设置"), _
    DisplayName("右")> _
       Public Property BRProperty() As Boolean
            Get
                Return bR
            End Get
            Set(ByVal value As Boolean)
                bR = value
                RaiseEvent ValueChanged()
            End Set
        End Property
        Dim bT As Boolean
        <CategoryAttribute("四维设置"), _
    DisplayName("上")> _
       Public Property BTProperty() As Boolean
            Get
                Return bT
            End Get
            Set(ByVal value As Boolean)
                bT = value
                RaiseEvent ValueChanged()
            End Set
        End Property
        Dim bB As Boolean
        <CategoryAttribute("四维设置"), _
    DisplayName("下")> _
       Public Property BBProperty() As Boolean
            Get
                Return bB
            End Get
            Set(ByVal value As Boolean)
                bB = value
                RaiseEvent ValueChanged()
            End Set
        End Property
    End Class

Public Sub New(ByVal ln As String)
    MyBase.new(ln)

    Me.m_bShowText = True

    'bDCText = New B4(True, False, False, True)
    'bDCScale = New B4(True, False, False, True)
    'bDc = New B4(True, False, False, True)

    '测试代码的时候，效果全开
    bDCText = New B4(True, True, True, True)
    bDCScale = New B4(True, True, True, True)
    bDc = New B4(True, True, True, True)

    m_XCells = 10
    m_YCells = 10
    m_LBPointXA = 0
    m_LBPointYA = 0
    m_LBPointY = 0
    m_LBPointX = 0

    m_XunitL = 1
    m_YuintL = 1

    m_ScaleL = 0.2


    linetype = FtkLineStipple.lsNone
    lineColor = Drawing.Color.Black
    lineWidth = 1

    End Sub

    '这些都是为了讨厌的VB事件逻辑啊
    Protected Sub New( _
      ByVal info As System.Runtime.Serialization.SerializationInfo, _
      ByVal context As System.Runtime.Serialization.StreamingContext)

        MyBase.New(info, context)

    End Sub

    '线条相关以及对应的处理程序

    Dim linetype As FtkLineStipple

    <CategoryAttribute("外观设置"), _
   DisplayName("线条类型")> _
   Public Overridable Property LinetypeProperty() As FtkLineStipple
        Get
            Return linetype
        End Get
        Set(ByVal value As FtkLineStipple)
            If linetype = value Then

            Else

                linetype = value

                Me.OnLnTypeChanged(linetype)

            End If


        End Set
    End Property


    Dim lineColor As Drawing.Color
    <CategoryAttribute("外观设置"), _
    DisplayName("线条颜色")> _
    Public Overridable Property LineColorProperty() As Drawing.Color
        Get
            Return lineColor
        End Get
        Set(ByVal value As Drawing.Color)

            If lineColor = value Then

            Else

                lineColor = value
                Me.OnLnClChanged(lineColor)
            End If


        End Set
    End Property
    Dim lineWidth As Double

    <CategoryAttribute("外观设置"), _
   DisplayName("线条宽度")> _
   Public Overridable Property LineWidthProperty() As Double
        Get
            Return lineWidth
        End Get
        Set(ByVal value As Double)
            If lineWidth = value Then

            Else

                lineWidth = value

                Me.OnLnWdChanged(lineWidth)

            End If



        End Set
    End Property

Private Sub OnLnWdChanged(ByVal d As Double)

    mapwin.set_ShapeLayerLineWidth(m_iLayer, d)
End Sub
Private Sub OnLnClChanged(ByVal cl As Drawing.Color)

    Dim ucl As UInt32 = RGB(cl.R, cl.G, cl.B)
    mapwin.set_ShapeLayerLineColor(m_iLayer, ucl)
End Sub
Private Sub OnLnTypeChanged(ByVal lt As MapWinGIS.tkLineStipple)

    Dim temp As MapWinGIS.tkLineStipple = Me.getLineType(lt)
    mapwin.set_ShapeLayerLineStipple(m_iLayer, temp)

End Sub




    Protected Sub NeedRedraw()
        Me.AllRedraw()
    End Sub


Dim bDCText As B4
    <CategoryAttribute("外观"), _
    DisplayName("坐标值")> _
    Public Property BDCTextProperty() As B4
        Get
            Return bDCText
        End Get
        Set(ByVal value As B4)

            bDCText = value
            AddHandler bDCText.ValueChanged, AddressOf NeedRedraw
            Me.AllRedraw()
        End Set
    End Property
Dim bDCScale As B4
    <CategoryAttribute("外观"), _
    DisplayName("刻度线")> _
    Public Property BDCScaleProperty() As B4
        Get
            Return bDCScale
        End Get
        Set(ByVal value As B4)
            bDCScale = value
            AddHandler bDCScale.ValueChanged, AddressOf NeedRedraw
            Me.AllRedraw()
        End Set
    End Property

Dim bDc As B4
<CategoryAttribute("外观"), _
DisplayName("坐标轴")> _
Public Property BDcProperty() As B4
    Get
        Return bDc
    End Get
    Set(ByVal value As B4)
            bDc = value
            AddHandler bDc.ValueChanged, AddressOf NeedRedraw
        Me.AllRedraw()

    End Set
End Property

'变化比例
Dim xScale As Double = 1

'特殊属性设置


    Public Sub SetGridProperty(ByVal m_LBPointXA As Double, ByVal m_LBPointYA As Double, ByVal m_LBPointX As Double, ByVal m_LBPointY As Double, ByVal m_XCells As Integer, ByVal m_YCells As Integer, ByVal m_XunitL As Double, ByVal m_YuintL As Double)

        Me.m_LBPointXA = m_LBPointXA
        Me.m_LBPointYA = m_LBPointYA

        Me.m_LBPointX = m_LBPointX
        Me.m_LBPointY = m_LBPointY

        Me.m_XCells = m_XCells
        Me.m_YCells = m_YCells

        Me.m_XunitL = m_XunitL
        Me.m_YuintL = m_YuintL

        Me.AllRedraw()

    End Sub


    Dim m_LBPointXA As Double
    <CategoryAttribute("特定设置"), _
      Browsable(False), _
 DisplayName("左下点绝对坐标X")> _
   Public Property LBPointXAProperty() As Double
        Get
            Return m_LBPointXA
        End Get
        Set(ByVal value As Double)
            If m_LBPointXA = value Then

            Else

                m_LBPointXA = value

                Me.AllRedraw()

            End If



        End Set
    End Property
    Dim m_LBPointYA As Double
    <CategoryAttribute("特定设置"), _
      Browsable(False), _
DisplayName("左下点绝对坐标Y")> _
   Public Property LBPointYAProperty() As Double
        Get
            Return m_LBPointYA
        End Get
        Set(ByVal value As Double)

            If m_LBPointYA = value Then

            Else

                m_LBPointYA = value
                Me.AllRedraw()

            End If



        End Set
    End Property


    Dim m_LBPointX As Double
    <CategoryAttribute("特定设置"), _
      Browsable(False), _
    DisplayName("左下点相对坐标X")> _
    Public Property LBPointXProperty() As Double
        Get
            Return m_LBPointX
        End Get
        Set(ByVal value As Double)
            If m_LBPointX = value Then
            Else

                m_LBPointX = value
                Me.AllRedraw()
            End If

        End Set
    End Property
    Dim m_LBPointY As Double
    <CategoryAttribute("特定设置"), _
      Browsable(False), _
    DisplayName("左下点相对坐标Y")> _
    Public Property LBPointYProperty() As Double
        Get
            Return m_LBPointY
        End Get
        Set(ByVal value As Double)
            If m_LBPointY = value Then

            Else

                m_LBPointY = value

                Me.AllRedraw()

            End If

        End Set
    End Property

    Dim m_XCells As Integer
    <CategoryAttribute("特定设置"), _
      Browsable(False), _
DisplayName("X轴单元格数")> _
   Public Property XCellsProperty() As Integer
        Get
            Return m_XCells
        End Get
        Set(ByVal value As Integer)
            If m_XCells = value Then

            Else

                If value < 0 Then
                    value = 0
                End If
                m_XCells = value
                Me.AllRedraw()

            End If



        End Set
    End Property
    Dim m_YCells As Integer
    <CategoryAttribute("特定设置"), _
      Browsable(False), _
DisplayName("Y轴单元格数")> _
   Public Property YCellsProperty() As Integer
        Get
            Return m_YCells
        End Get
        Set(ByVal value As Integer)

            If m_YCells = value Then
            Else

                If value < 0 Then
                    value = 0
                End If
                m_YCells = value
                Me.AllRedraw()


            End If


        End Set
    End Property

    Dim m_XunitL As Double
    <CategoryAttribute("特定设置"), _
      Browsable(False), _
DisplayName("X轴单元格长度")> _
   Public Property XunitLProperty() As Double
        Get
            Return m_XunitL
        End Get
        Set(ByVal value As Double)

            If m_XunitL = value Then
            Else

                If value < 0 Then
                    value = 0
                End If
                m_XunitL = value
                Me.AllRedraw()

            End If



        End Set
    End Property

    Dim m_YuintL As Double
    <CategoryAttribute("特定设置"), _
     Browsable(False), _
DisplayName("Y轴单元格长度")> _
   Public Property YuintLProperty() As Double
        Get
            Return m_YuintL
        End Get
        Set(ByVal value As Double)
            If m_YuintL = value Then

            Else

                If value < 0 Then
                    value = 0
                End If
                m_YuintL = value
                Me.AllRedraw()

            End If



        End Set
    End Property

    Dim m_ScaleL As Double
    <CategoryAttribute("特定设置"), _
    DisplayName("刻度线长度")> _
    Public Property ScaleLProperty() As Double
        Get
            Return m_ScaleL
        End Get
        Set(ByVal value As Double)
            If m_ScaleL = value Then
            Else

                If value < 0 Then
                    value = 0
                End If
                m_ScaleL = value
                Me.AllRedraw()

            End If

        End Set
    End Property


    Protected Class Point3d
        Public Sub New(ByVal a As Double, ByVal b As Double, ByVal c As Double)
            x = a
            y = b
            z = c

        End Sub

        Public x As Double
        Public y As Double
        Public z As Double

    End Class

    Protected Sub DrawBrifText(ByVal p3s As List(Of Point3d), ByVal uclr As UInt32, ByVal length As Double, ByVal bHorizontal As Boolean, ByVal just As tkHJustification)
        Dim dBrif As Double
        If bHorizontal Then

            dBrif = length / (Me.xScale * Me.m_TextFont.Size * 6)


        Else

            dBrif = length / (Me.xScale * Me.m_TextFont.Size * 12)

        End If

        If dBrif < 4 Then
            If bHorizontal Then
                dBrif = 4
            Else
                dBrif = 8
            End If

        End If


        Dim len As Double = p3s.Count

        '当需要精简操作时
        If len > dBrif Then
            Dim ptemp As New List(Of Point3d)

            Dim part As Double = len / dBrif

            For i As Integer = 0 To len - 1 Step part

                Dim p As Point3d = p3s.Item(i)
                mapwin.AddLabelEx(m_iLayer, p.z, uclr, p.x, p.y, just, 0)


            Next

        Else

            For Each p As Point3d In p3s

                mapwin.AddLabelEx(m_iLayer, p.z, uclr, p.x, p.y, just, 0)
            Next

        End If





    End Sub



    Protected Overrides Sub DrawMySelf()

        If Me.BDcProperty.BLProperty Then
            Me.DrawAxisL()
        End If
        If Me.BDcProperty.BRProperty Then
            Me.DrawAxisR()
        End If
        If Me.BDcProperty.BTProperty Then
            Me.DrawAxisT()
        End If
        If Me.BDcProperty.BBProperty Then
            Me.DrawAxisB()
        End If

    End Sub

    Protected Overrides Sub DrawText()


        If Not m_bShowText Then
            Return

        End If

        '首先还是要清除掉以前绘制的内容呢
        mapwin.ClearLabels(m_iLayer)

        mapwin.LayerFont(m_iLayer, m_TextFont.Name, m_TextFont.Size)


        Dim xOrg As Double = Me.LBPointXAProperty
        Dim yOrg As Double = Me.LBPointYAProperty
        Dim xcells As Integer = Me.XCellsProperty
        Dim ycells As Integer = Me.YCellsProperty

        'Dim gridspace As Double
        Dim xspace As Double = Me.XunitLProperty
        Dim yspace As Double = Me.YuintLProperty


        Dim xRe As Double = Me.LBPointXProperty
        Dim yRe As Double = Me.LBPointYProperty

        Dim alen As Double = Me.ScaleLProperty


        Dim uclr As UInt32 = RGB(Me.m_TextColor.R, Me.m_TextColor.G, Me.m_TextColor.B)

        Dim ps As New List(Of Point3d)


        If Me.BDCTextProperty.BLProperty Then


            ps.Clear()

            '下面开始万恶的文字绘制


            Dim dVal As Double
            Dim x As Double
            Dim y As Double




            For i As Integer = 0 To ycells
                dVal = yRe + i * yspace
                x = xOrg - alen
                y = yOrg + i * yspace

                '由于软件本身BUG所引入的纠正代码

                x = x - Me.xScale * Me.m_TextFont.Size * 2
                y = y + Me.xScale * Me.m_TextFont.Size * 0.8

                'x = x - Me.xScale * Me.m_TextFont.Size
                'y = y + Me.xScale * Me.m_TextFont.Size


                'mapwin.AddLabelEx(m_iLayer, dVal.ToString(), uclr, x, y, tkHJustification.hjLeft, 0)

                Dim p As New Point3d(x, y, dVal)
                ps.Add(p)


            Next
            Me.DrawBrifText(ps, uclr, yspace * ycells, False, tkHJustification.hjLeft)

        End If


        If Me.BDCTextProperty.BRProperty Then

            ps.Clear()

            '下面开始万恶的文字绘制


            Dim dVal As Double
            Dim x As Double
            Dim y As Double



            For i As Integer = 0 To ycells
                dVal = yRe + i * yspace
                x = xOrg + xspace * xcells + alen
                y = yOrg + i * yspace


                '由于软件本身BUG所引入的纠正代码

                x = x + Me.xScale * Me.m_TextFont.Size
                y = y + Me.xScale * Me.m_TextFont.Size * 1.8

                'x = x + Me.xScale * Me.m_TextFont.Size
                'y = y + Me.xScale * Me.m_TextFont.Size

                '  mapwin.AddLabelEx(m_iLayer, dVal.ToString(), uclr, x, y, tkHJustification.hjRight, 0)

                Dim p As New Point3d(x, y, dVal)
                ps.Add(p)


            Next
            Me.DrawBrifText(ps, uclr, yspace * ycells, False, tkHJustification.hjRight)

        End If


        If Me.BDCTextProperty.BTProperty Then

            ps.Clear()

            '下面开始万恶的文字绘制
            '等有了比例尺，上面的轴兄弟你才能解脱啊


            Dim dVal As Double
            Dim x As Double
            Dim y As Double



            For i As Integer = 0 To xcells
                dVal = xRe + i * xspace
                x = xOrg + i * xspace
                y = yOrg + ycells * yspace + alen

                '由于软件本身BUG所引入的纠正代码


                y = y + Me.xScale * Me.m_TextFont.Size * 1.8

                'y = y + Me.xScale * Me.m_TextFont.Size

                ' mapwin.AddLabelEx(m_iLayer, dVal.ToString(), uclr, x, y, tkHJustification.hjCenter, 0)


                Dim p As New Point3d(x, y, dVal)
                ps.Add(p)


            Next
            Me.DrawBrifText(ps, uclr, xspace * xcells, True, tkHJustification.hjCenter)

        End If


        If Me.BDCTextProperty.BBProperty Then

            ps.Clear()

            '下面开始万恶的文字绘制

            Dim dVal As Double
            Dim x As Double
            Dim y As Double



            For i As Integer = 0 To xcells
                dVal = xRe + i * xspace
                x = xOrg + i * xspace
                y = yOrg - alen

                ' mapwin.AddLabelEx(m_iLayer, dVal.ToString(), uclr, x, y, tkHJustification.hjCenter, 0)



                Dim p As New Point3d(x, y, dVal)
                ps.Add(p)


            Next
            Me.DrawBrifText(ps, uclr, xspace * xcells, True, tkHJustification.hjCenter)

        End If

    End Sub



    Public Overrides Sub OnExtentsChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim p1 As New MapWinGIS.Point
        Dim p2 As New MapWinGIS.Point

        mapwin.PixelToProj(0, 0, p1.x, p1.y)
        mapwin.PixelToProj(1, 1, p2.x, p2.y)

        xScale = p2.x - p1.x

        Me.DrawText()
        'Me.DrawMySelf()

    End Sub


    '内部功能函数
    Private Sub DrawAxisL()

        Dim xOrg As Double = Me.LBPointXAProperty
        Dim yOrg As Double = Me.LBPointYAProperty
        Dim xcells As Integer = Me.XCellsProperty
        Dim ycells As Integer = Me.YCellsProperty

        'Dim gridspace As Double
        Dim xspace As Double = Me.XunitLProperty
        Dim yspace As Double = Me.YuintLProperty


        Dim xRe As Double = Me.LBPointXProperty
        Dim yRe As Double = Me.LBPointYProperty



        Dim alen As Double = Me.ScaleLProperty

        '直接修改alen就可以影响此属性成相对的坐标值

        ' alen = alen * Me.xScale





        '开始绘制啦

        Dim pt1 As MapWinGIS.Point
        Dim pt2 As MapWinGIS.Point




        Dim sfGrid As Shapefile

        sfGrid = mapwin.get_GetObject(m_iLayer)

        '以下命名规则为，与x轴相交的点的集合，叫做xpts


        Dim ny As Integer = (ycells + 1) * 2



        Dim ypts(ny) As MapWinGIS.Point





        For j As Integer = 0 To ycells


            pt1 = New Point()
            pt1.x = xOrg
            pt1.y = yOrg + j * yspace
            ypts(2 * j) = pt1

            pt2 = New Point()
            ' pt2.x = xcells * gridspace + xOrg

            pt2.x = xOrg - alen



            pt2.y = yOrg + j * yspace

            ypts(2 * j + 1) = pt2





        Next

        sfGrid.StartEditingShapes(True)




        If Me.BDCScaleProperty.BLProperty Then



            For h As Integer = 0 To ycells

                Dim shp As New Shape
                shp.ShapeType = ShpfileType.SHP_POLYLINE
                Dim ptIndex As Integer = 0

                shp.InsertPoint(ypts(2 * h), ptIndex)
                shp.InsertPoint(ypts(2 * h + 1), ptIndex)




                Dim shpIndex As Integer = sfGrid.NumShapes

                sfGrid.EditInsertShape(shp, shpIndex)

                sfGrid.EditCellValue(0, shpIndex, shpIndex)

            Next


        End If


        '那条主轴线得画出来，真正的轴
        Dim shp1 As New Shape
        shp1.ShapeType = ShpfileType.SHP_POLYLINE
        Dim ptIndex1 As Integer = 0
        pt1 = New MapWinGIS.Point()
        pt1.x = xOrg
        pt1.y = yOrg

        pt2 = New MapWinGIS.Point()
        pt2.x = xOrg
        pt2.y = yOrg + ycells * yspace

        shp1.InsertPoint(pt1, ptIndex1)
        shp1.InsertPoint(pt2, ptIndex1)




        Dim shpIndex1 As Integer = sfGrid.NumShapes

        sfGrid.EditInsertShape(shp1, shpIndex1)

        sfGrid.EditCellValue(0, shpIndex1, shpIndex1)




        sfGrid.StopEditingShapes()




    End Sub

    Private Sub DrawAxisR()

        Dim xOrg As Double = Me.LBPointXAProperty
        Dim yOrg As Double = Me.LBPointYAProperty
        Dim xcells As Integer = Me.XCellsProperty
        Dim ycells As Integer = Me.YCellsProperty

        'Dim gridspace As Double
        Dim xspace As Double = Me.XunitLProperty
        Dim yspace As Double = Me.YuintLProperty


        Dim xRe As Double = Me.LBPointXProperty
        Dim yRe As Double = Me.LBPointYProperty

        Dim alen As Double = Me.ScaleLProperty

        '直接修改alen就可以影响此属性成相对的坐标值

        ' alen = alen * Me.xScale


        '开始绘制啦
        Dim sfGrid As Shapefile

        sfGrid = mapwin.get_GetObject(m_iLayer)

        '以下命名规则为，与x轴相交的点的集合，叫做xpts

        'Dim nx As Integer = (xcells + 1) * 2
        Dim ny As Integer = (ycells + 1) * 2

        ' Dim xpts(nx) As MapWinGIS.Point

        Dim ypts(ny) As MapWinGIS.Point

        Dim pt1 As MapWinGIS.Point
        Dim pt2 As MapWinGIS.Point



        For j As Integer = 0 To ycells


            pt1 = New Point()
            ' pt1.x = xOrg
            pt1.x = xOrg + xcells * xspace

            pt1.y = yOrg + j * yspace
            ypts(2 * j) = pt1

            pt2 = New Point()
            ' pt2.x = xcells * gridspace + xOrg

            ' pt2.x = xOrg - alen
            pt2.x = xOrg + alen + xcells * xspace



            pt2.y = yOrg + j * yspace

            ypts(2 * j + 1) = pt2





        Next

        sfGrid.StartEditingShapes(True)


        If Me.BDCScaleProperty.BRProperty Then




            For h As Integer = 0 To ycells

                Dim shp As New Shape
                shp.ShapeType = ShpfileType.SHP_POLYLINE
                Dim ptIndex As Integer = 0

                shp.InsertPoint(ypts(2 * h), ptIndex)
                shp.InsertPoint(ypts(2 * h + 1), ptIndex)




                Dim shpIndex As Integer = sfGrid.NumShapes

                sfGrid.EditInsertShape(shp, shpIndex)

                sfGrid.EditCellValue(0, shpIndex, shpIndex)

            Next

        End If


        '那条主轴线得画出来，真正的轴
        Dim shp1 As New Shape
        shp1.ShapeType = ShpfileType.SHP_POLYLINE
        Dim ptIndex1 As Integer = 0
        pt1 = New MapWinGIS.Point()
        pt1.x = xOrg + xspace * xcells
        pt1.y = yOrg

        pt2 = New MapWinGIS.Point()
        pt2.x = xOrg + xspace * xcells
        pt2.y = yOrg + ycells * yspace

        shp1.InsertPoint(pt1, ptIndex1)
        shp1.InsertPoint(pt2, ptIndex1)




        Dim shpIndex1 As Integer = sfGrid.NumShapes

        sfGrid.EditInsertShape(shp1, shpIndex1)

        sfGrid.EditCellValue(0, shpIndex1, shpIndex1)




        sfGrid.StopEditingShapes()






    End Sub

    Private Sub DrawAxisT()
        Dim xOrg As Double = Me.LBPointXAProperty
        Dim yOrg As Double = Me.LBPointYAProperty
        Dim xcells As Integer = Me.XCellsProperty
        Dim ycells As Integer = Me.YCellsProperty

        'Dim gridspace As Double
        Dim xspace As Double = Me.XunitLProperty
        Dim yspace As Double = Me.YuintLProperty


        Dim xRe As Double = Me.LBPointXProperty
        Dim yRe As Double = Me.LBPointYProperty

        Dim alen As Double = Me.ScaleLProperty

        '直接修改alen就可以影响此属性成相对的坐标值

        ' alen = alen * Me.xScale



        '开始绘制啦
        Dim sfGrid As Shapefile

        sfGrid = mapwin.get_GetObject(m_iLayer)

        '以下命名规则为，与x轴相交的点的集合，叫做xpts

        Dim nx As Integer = (xcells + 1) * 2


        Dim xpts(nx) As MapWinGIS.Point



        Dim pt1 As MapWinGIS.Point
        Dim pt2 As MapWinGIS.Point

        For i As Integer = 0 To xcells

            pt1 = New Point()
            pt1.x = xOrg + i * xspace
            pt1.y = yOrg + yspace * ycells
            xpts(2 * i) = pt1

            pt2 = New Point()
            pt2.x = xOrg + i * xspace

            ' pt2.y = (ycells) * gridspace + yOrg
            pt2.y = yOrg + alen + yspace * ycells


            xpts(2 * i + 1) = pt2




        Next

        sfGrid.StartEditingShapes(True)

        If Me.BDCScaleProperty.BTProperty Then

            For k As Integer = 0 To xcells

                Dim shp As New Shape
                shp.ShapeType = ShpfileType.SHP_POLYLINE
                Dim ptIndex As Integer = 0

                shp.InsertPoint(xpts(2 * k), ptIndex)
                shp.InsertPoint(xpts(2 * k + 1), ptIndex)




                Dim shpIndex As Integer = sfGrid.NumShapes

                sfGrid.EditInsertShape(shp, shpIndex)

                sfGrid.EditCellValue(0, shpIndex, shpIndex)

            Next

        End If


        '那条主轴线得画出来，真正的轴
        Dim shp1 As New Shape
        shp1.ShapeType = ShpfileType.SHP_POLYLINE
        Dim ptIndex1 As Integer = 0
        pt1 = New MapWinGIS.Point()
        pt1.x = xOrg
        pt1.y = yOrg + yspace * ycells

        pt2 = New MapWinGIS.Point()
        pt2.x = xOrg + xspace * xcells
        pt2.y = yOrg + ycells * yspace

        shp1.InsertPoint(pt1, ptIndex1)
        shp1.InsertPoint(pt2, ptIndex1)




        Dim shpIndex1 As Integer = sfGrid.NumShapes

        sfGrid.EditInsertShape(shp1, shpIndex1)

        sfGrid.EditCellValue(0, shpIndex1, shpIndex1)




        sfGrid.StopEditingShapes()





    End Sub


    Private Sub DrawAxisB()
        Dim xOrg As Double = Me.LBPointXAProperty
        Dim yOrg As Double = Me.LBPointYAProperty
        Dim xcells As Integer = Me.XCellsProperty
        Dim ycells As Integer = Me.YCellsProperty

        'Dim gridspace As Double
        Dim xspace As Double = Me.XunitLProperty
        Dim yspace As Double = Me.YuintLProperty


        Dim xRe As Double = Me.LBPointXProperty
        Dim yRe As Double = Me.LBPointYProperty

        Dim alen As Double = Me.ScaleLProperty


        '直接修改alen就可以影响此属性成相对的坐标值

        'alen = alen * Me.xScale


        '开始绘制啦
        Dim sfGrid As Shapefile

        sfGrid = mapwin.get_GetObject(m_iLayer)
        '以下命名规则为，与x轴相交的点的集合，叫做xpts

        Dim nx As Integer = (xcells + 1) * 2


        Dim xpts(nx) As MapWinGIS.Point



        Dim pt1 As MapWinGIS.Point
        Dim pt2 As MapWinGIS.Point

        For i As Integer = 0 To xcells

            pt1 = New Point()
            pt1.x = xOrg + i * xspace
            pt1.y = yOrg
            xpts(2 * i) = pt1

            pt2 = New Point()
            pt2.x = xOrg + i * xspace

            ' pt2.y = (ycells) * gridspace + yOrg
            pt2.y = yOrg - alen


            xpts(2 * i + 1) = pt2




        Next

        sfGrid.StartEditingShapes(True)


        If Me.BDCScaleProperty.BBProperty Then

            For k As Integer = 0 To xcells

                Dim shp As New Shape
                shp.ShapeType = ShpfileType.SHP_POLYLINE
                Dim ptIndex As Integer = 0

                shp.InsertPoint(xpts(2 * k), ptIndex)
                shp.InsertPoint(xpts(2 * k + 1), ptIndex)




                Dim shpIndex As Integer = sfGrid.NumShapes

                sfGrid.EditInsertShape(shp, shpIndex)

                sfGrid.EditCellValue(0, shpIndex, shpIndex)

            Next

        End If

        '那条主轴线得画出来，真正的轴
        Dim shp1 As New Shape
        shp1.ShapeType = ShpfileType.SHP_POLYLINE
        Dim ptIndex1 As Integer = 0
        pt1 = New MapWinGIS.Point()
        pt1.x = xOrg
        pt1.y = yOrg

        pt2 = New MapWinGIS.Point()
        pt2.x = xOrg + xspace * xcells
        pt2.y = yOrg

        shp1.InsertPoint(pt1, ptIndex1)
        shp1.InsertPoint(pt2, ptIndex1)




        Dim shpIndex1 As Integer = sfGrid.NumShapes

        sfGrid.EditInsertShape(shp1, shpIndex1)

        sfGrid.EditCellValue(0, shpIndex1, shpIndex1)



        sfGrid.StopEditingShapes()





    End Sub

    Public Overrides Sub InitNewLayer(ByRef m As AxMapWinGIS.AxMap, ByVal OutPath As String)

        Dim sf As New Shapefile
        Dim strPath(2) As String


        'strPath(0) = "C:\temp\" + lname + ".shp"
        'strPath(1) = "C:\temp\" + lname + ".dbf"
        'strPath(2) = "C:\temp\" + lname + ".shx"

        'If System.IO.File.Exists(strPath(0)) Then
        '    System.IO.File.Delete(strPath(0))
        '    System.IO.File.Delete(strPath(1))
        '    System.IO.File.Delete(strPath(2))

        'End If

        sf.CreateNew(strPath(0), MapWinGIS.ShpfileType.SHP_POLYLINE)




        Dim f As New Field

        f = New Field
        f.Name = "Name"
        f.Type = FieldType.STRING_FIELD
        f.Width = 50

        sf.StartEditingShapes(True)
        sf.EditInsertField(f, 0)
        sf.StopEditingShapes(True, True)


        '加入载入的逻辑

        Dim strSave As String = OutPath + lname + ".shp"

        strPath(0) = OutPath + lname + ".shp"
        strPath(1) = OutPath + lname + ".dbf"
        strPath(2) = OutPath + lname + ".shx"

        For i As Integer = 0 To strPath.Length - 1
            If System.IO.File.Exists(strPath(i)) Then
                Try
                    System.IO.File.SetAttributes(strPath(i), IO.FileAttributes.Normal)
                    System.IO.File.Delete(strPath(i))
                Catch ex As Exception

                End Try

            End If
        Next

        Dim bS As Boolean = sf.SaveAs(strSave)

        If Not bS Then
            System.Windows.Forms.MessageBox.Show(lname + "文件创建失败！，请查看电脑软件使用权限")

        End If

        fname = strSave
        Me.InitLayer(m)
    End Sub

    Public Overrides Sub InitProp()

        Me.OnLnClChanged(lineColor)
        Me.OnLnWdChanged(lineWidth)
        Me.OnLnTypeChanged(linetype)


        AddHandler bDCText.ValueChanged, AddressOf NeedRedraw
        AddHandler bDCScale.ValueChanged, AddressOf NeedRedraw
        AddHandler bDc.ValueChanged, AddressOf NeedRedraw


    End Sub
End Class
